- 
          
- 
                Notifications
    You must be signed in to change notification settings 
- Fork 1.5k
          [Fix] no-unused-modules: don't error out when running with flat config and an eslintrc isn't present
          #3116
        
          New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks pretty good, thanks!
| Codecov ReportAttention: Patch coverage is  
 
 Additional details and impacted files@@            Coverage Diff             @@
##             main    #3116      +/-   ##
==========================================
+ Coverage   90.45%   94.99%   +4.54%     
==========================================
  Files          84       83       -1     
  Lines        3634     3618      -16     
  Branches     1279     1276       -3     
==========================================
+ Hits         3287     3437     +150     
+ Misses        347      181     -166     ☔ View full report in Codecov by Sentry. | 
4a50098    to
    d5ba9af      
    Compare
  
    | Addressed lint errors | 
d5ba9af    to
    a515ac9      
    Compare
  
    no-unused-modules: don't error out when running with flat config and an eslintrc isn't present
      7ba8372    to
    bc01442      
    Compare
  
    | Updated, based on feedback in #3079 to not attempt to avoid the error, but to instead rethrow with a more informative message. I updated the PR description to reflect the new approach. There's not a great way to test this now. With the integration tests before, we could remove the rc config, run lint, and observe that it didn't error out. Now we're wanting it to error out when no rc is present, and there's not a great way to recreate that in the rule's unit tests or in integration tests that don't throw (unless we write a custom node script to serve as an integration test). Thoughts? | 
bc01442    to
    e17e073      
    Compare
  
    | I suppose we could have a test make a temp dir (using  | 
e17e073    to
    9acd806      
    Compare
  
    | 
 Added a test that does the following: 
 | 
dda50b9    to
    133aeeb      
    Compare
  
    691aba5    to
    322ef5f      
    Compare
  
    | @ljharb I got this about where I want it, except for one question to you. I added the test to the existing set of unit tests just because all the CI plumbing was already in place to add it there. Though, it doesn't really feel right for it to be there, since it's more of an integration test. Would you rather it be where I have it now, or add a new workflow to CI for doing this kind of integration testing? | 
| I think that it's fine where it is to land this, but it might make sense to move it in a followup? … although i do see there's 2 uncovered lines in the diff | 
| 
 Sounds good 
 Do you mean the catch block? If so, that's because the new test isn't really contributing to the coverage report, since it's building the plugin and running lint as a separate exec command. | 
… no eslintrc is present This change adjusts what we're doing if an error is thrown while attempting to enumerate lintable files in the no-used-modules rule, when users are running with flat config. Now, if FileEnumerator throws due to a lack of eslintrc and the user is running with flat config, we catch the error and rethrow with a more informative message. I also cleaned up the original aspects of the implementation that was using the proposed eslint context functions, since that proposal was walked back and the API was never introduced. Note: This isn't an ideal state, since this rule still relies on the legacy api to understand what needs to be ignored. Remaining tethered to the legacy config system is going to need to be solved at some point. Fixes import-js#3079
322ef5f    to
    e5edf49      
    Compare
  
    | datasource | package | from | to | | ---------- | -------------------- | ------ | ------ | | npm | eslint-plugin-import | 2.31.0 | 2.32.0 | ## [v2.32.0](https://github.com/import-js/eslint-plugin-import/blob/HEAD/CHANGELOG.md#2320---2025-06-20) ##### Added - add \[`enforce-node-protocol-usage`] rule and `import/node-version` setting (\[[#3024](import-js/eslint-plugin-import#3024)], thanks \[[@GoldStrikeArch](https://github.com/GoldStrikeArch)] and \[[@sevenc-nanashi](https://github.com/sevenc-nanashi)]) - add TypeScript types (\[[#3097](import-js/eslint-plugin-import#3097)], thanks \[[@G-Rath](https://github.com/G-Rath)]) - \[`extensions`]: add \`pathGroupOverrides to allow enforcement decision overrides based on specifier (\[[#3105](import-js/eslint-plugin-import#3105)], thanks \[[@Xunnamius](https://github.com/Xunnamius)]) - \[`order`]: add `sortTypesGroup` option to allow intragroup sorting of type-only imports (\[[#3104](import-js/eslint-plugin-import#3104)], thanks \[[@Xunnamius](https://github.com/Xunnamius)]) - \[`order`]: add `newlines-between-types` option to control intragroup sorting of type-only imports (\[[#3127](import-js/eslint-plugin-import#3127)], thanks \[[@Xunnamius](https://github.com/Xunnamius)]) - \[`order`]: add `consolidateIslands` option to collapse excess spacing for aesthetically pleasing imports (\[[#3129](import-js/eslint-plugin-import#3129)], thanks \[[@Xunnamius](https://github.com/Xunnamius)]) ##### Fixed - \[`no-unused-modules`]: provide more meaningful error message when no .eslintrc is present (\[[#3116](import-js/eslint-plugin-import#3116)], thanks \[[@michaelfaith](https://github.com/michaelfaith)]) - configs: added missing name attribute for eslint config inspector (\[[#3151](import-js/eslint-plugin-import#3151)], thanks \[[@NishargShah](https://github.com/NishargShah)]) - \[`order`]: ensure arcane imports do not cause undefined behavior (\[[#3128](import-js/eslint-plugin-import#3128)], thanks \[[@Xunnamius](https://github.com/Xunnamius)]) - \[`order`]: resolve undefined property access issue when using `named` ordering (\[[#3166](import-js/eslint-plugin-import#3166)], thanks \[[@Xunnamius](https://github.com/Xunnamius)]) - \[`enforce-node-protocol-usage`]: avoid a crash with some TS code (\[[#3173](import-js/eslint-plugin-import#3173)], thanks \[[@ljharb](https://github.com/ljharb)]) - \[`order`]: codify invariants from docs into config schema (\[[#3152](import-js/eslint-plugin-import#3152)], thanks \[[@Xunnamius](https://github.com/Xunnamius)]) ##### Changed - \[Docs] \[`extensions`], \[`order`]: improve documentation (\[[#3106](import-js/eslint-plugin-import#3106)], thanks \[[@Xunnamius](https://github.com/Xunnamius)]) - \[Docs] add flat config guide for using `tseslint.config()` (\[[#3125](import-js/eslint-plugin-import#3125)], thanks \[[@lnuvy](https://github.com/lnuvy)]) - \[Docs] add missing comma (\[[#3122](import-js/eslint-plugin-import#3122)], thanks \[[@RyanGst](https://github.com/RyanGst)]) - \[readme] Update flatConfig example to include typescript config (\[[#3138](import-js/eslint-plugin-import#3138)], thanks \[[@intellix](https://github.com/intellix)]) - \[Refactor] \[`order`]: remove unnecessary negative check (\[[#3167](import-js/eslint-plugin-import#3167)], thanks \[[@JounQin](https://github.com/JounQin)]) - \[Docs] \[`no-unused-modules`]: add missing double quote (\[[#3191](import-js/eslint-plugin-import#3191)], thanks \[[@albertpastrana](https://github.com/albertpastrana)]) - \[Docs] `no-restricted-paths`: clarify wording and fix errors (\[[#3172](import-js/eslint-plugin-import#3172)], thanks \[[@greim](https://github.com/greim)])
This change adjusts what we're doing if an error is thrown while attempting to enumerate lintable files in the
no-used-modulesrule, when users are running with flat config. Now, ifFileEnumeratorthrows due to a lack of eslintrc and the user is running with flat config, we catch the error and rethrow with a more informative message.I also cleaned up the original aspects of the implementation that was using the proposed eslint context functions, since that proposal was walked back and the API was never introduced.
Note: This isn't an ideal state, since this rule still relies on the legacy api to understand what needs to be ignored. Remaining tethered to the legacy config system is going to need to be solved at some point.
Fixes #3079